# frozen_string_literal: true

class Formula < ApplicationRecord
  belongs_to :formulable, polymorphic: true

  before_create :use_default_type

  validates :formulable_type, presence: true
  validates :formulable_id, presence: true
  validates :content, presence: true

  def fire(**params)
    # ScriptSandbox.eval_script content, params
    logger.debug { params }
  end

  private

  def use_default_type
    self.type = Formula::Mrb.name if type.nil?
  end
end
